package com.ss.android.article.base.feature.update.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.update.a.d;
import com.ss.android.article.base.feature.update.a.e;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr.b;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr.o$a;
import com.ss.android.article.base.ui.NoDataViewFactory$ImgType;
import com.ss.android.article.base.ui.ac;
import com.ss.android.article.base.ui.ad;
import com.ss.android.article.base.ui.NoNetView;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.activity.FragmentActivity;
import com.ss.android.newmedia.BaseAppData;

import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.Iterator;

public class UpdateDetailActivity extends FragmentActivity implements o$a, b {
    int a;
    boolean b;
    private Context c;
    private UpdateItemMgr d;
    private long e;
    private long f;
    private String g;
    private long h;
    private int i;
    private e j;
    private boolean k;
    private boolean l;
    private long m;
    private d n;
    private View o;
    private View p;
    private boolean q;
    private boolean r;
    private WeakReference s;
    private String t;
    private String u;
    private long v;
    private boolean w;
    private NoNetView x;
    private long y;

    public UpdateDetailActivity() {

        this.q = false;
        this.r = false;
        this.a = 4;
        this.y = 0;
    }

    public static void a(Context arg16, Fragment arg17, long arg18, e arg20, boolean arg21, long arg22, boolean arg24) {
        if (arg18 > 0 && arg16 != null) {
            UpdateItemMgr.getInstance(arg16).f = arg20;
            Intent v2 = UpdateDetailActivity.a(arg16, arg18, 0, 0, 5, 0, null, arg21, arg22);
            v2.putExtra("replay_zz_comment", arg24);
            if (arg17 != null) {
                arg17.startActivityForResult(v2, 100);
            } else {
                arg16.startActivity(v2);
            }
        }
    }

    public static void a(Context arg15, long arg16, long arg18, long arg20, String arg22) {
        if (arg16 > 0 && arg15 != null) {
            UpdateItemMgr.getInstance(arg15).f = null;
            arg15.startActivity(UpdateDetailActivity.a(arg15, arg16, arg18, 4, -1, arg20, arg22, false, 0));
        }
    }

    private static Intent a(Context arg7, long arg8, long arg10, int arg12, int arg13, long arg14, String arg16, boolean arg17, long arg18) {
        Intent v2 = new Intent(arg7, UpdateDetailActivity.class);
        if (arg10 > 0) {
            v2.putExtra("create_time", arg10);
        }

        if (arg13 > 0) {
            v2.putExtra("update_item_source", arg13);
        }

        if (arg13 == 5) {
            v2.putExtra("comment_id", arg8);
        } else {
            v2.putExtra("id", arg8);
        }

        if (!android.support.design.a.isTextEmpty((String) null)) {
            v2.putExtra("explict_desc", (String) null);
        }

        v2.putExtra("view_comments", false);
        v2.putExtra("item_type", arg12);
        if (arg14 > 0) {
            v2.putExtra("update_comment_id", arg14);
        }

        if (!android.support.design.a.isTextEmpty(arg16)) {
            v2.putExtra("update_user_str", arg16);
        }

        v2.putExtra("ad_id", arg18);
        v2.putExtra("show_comment_dialog", arg17);
        return v2;
    }

    static void a(UpdateDetailActivity arg0) {
        arg0.onBackBtnClick();
    }

    private void a(boolean arg3) {
        if (this.x != null) {
            this.x.setVisibility(View.GONE);
        }

        Object v0 = null;
        if (this.s != null) {
            v0 = this.s.get();
        }

        if (v0 != null) {
            if (arg3) {
                this.getSupportFragmentManager().beginTransaction().remove(((Fragment) v0)).commitAllowingStateLoss();
                this.c();
            } else {
                ((g) v0).c();
            }
        } else if (arg3) {
            this.c();
        } else {
            this.b();
        }
    }

    public final void a() {
        this.isViewValid();
    }

    final void a(int arg11) {
        long v8 = 0;
        Object v7 = null;
        int v6 = 5;
        long v0 = arg11 == v6 ? this.h : this.e;
        if (v0 > v8) {
            if (Logger.debug()) {
                Logger.d("UpdateDetailActivity", "load update item detail async " + this.e);
            }

            if (this.d != null) {
                UpdateItemMgr v2 = this.d;
                if (v0 > v8) {
                    v2.h.addTask(Long.valueOf(v0), Integer.valueOf(arg11), v7, v7);
                }
            }

            if (arg11 != v6 && this.o != null) {
                UIUtils.setVisibility(this.o, 0);
            }

            if (this.p == null) {
                return;
            }

            UIUtils.setVisibility(this.p, 8);
        }
    }

    public final void a(long arg4) {
        if ((this.isViewValid()) && arg4 == this.e) {
            Object v0 = this.s != null ? this.s.get() : null;
            if (v0 != null) {
                ((g) v0).c();
                if (!((g) v0).w) {
                    ((g) v0).b();
                }
            }

            this.b(false);
        }
    }

    public final void a(long arg10, e arg12) {
        int v8 = 5;
        if (this.isViewValid()) {
            if (this.a == v8) {
                if (arg12 != null && arg12.a != null) {
                    this.e = arg12.a.i;
                }

                this.j = arg12;
            } else {
                if (arg10 == this.e) {
                } else {
                    return;
                }
            }

            UIUtils.setVisibility(this.o, 8);
            if (arg12 != null) {
                this.d.f = arg12;
                this.n = (com.ss.android.article.base.feature.update.a.d) arg12.a;
                if ((this.b) && this.n != null) {
                    AppData.getInstance().a(this.e, this.n.a, this.n.b, this.n.c);
                }

                this.j = arg12;
                if (this.h > 0) {
                    CallbackCenter.TYPE v0 = BaseAppData.callbackTypeCommentExtraInfoChanged;
                    Object[] v1 = new Object[v8];
                    v1[0] = BaseAppData.callbackTypeCommentExtraInfoChanged;
                    v1[1] = Long.valueOf(this.h);
                    v1[2] = Integer.valueOf(this.n.c);
                    v1[3] = Integer.valueOf(this.n.b);
                    v1[4] = Boolean.valueOf(this.n.a);
                    CallbackCenter.notifyCallback(v0, v1);
                }

                this.b(false);
                Object v1_1 = this.s != null ? this.s.get() : null;
                if (v1_1 == null) {
                    return;
                }

                long v2 = this.e;
                if (((g) v1_1).m != null) {
                    ((g) v1_1).d = v2;
                    ((g) v1_1).l = ((g) v1_1).m.a(((g) v1_1).d);
                    if (((g) v1_1).l != null) {
                        ((g) v1_1).j = (com.ss.android.article.base.feature.update.a.d) ((g) v1_1).l.a;
                        if (((g) v1_1).j != null) {
                            ((g) v1_1).k = ((g) v1_1).j.o;
                        }

                        if (!((g) v1_1).i) {
                        } else if (((g) v1_1).r == null) {
                        } else if (((g) v1_1).r.isShowing()) {
                        } else if (((g) v1_1).j == null) {
                        } else {
                            ((g) v1_1).r.a(((g) v1_1).e());
                            ((g) v1_1).i = false;
                        }
                    }
                }

                ((g) v1_1).q.a(((g) v1_1).f());
                ((g) v1_1).c();
                ((g) v1_1).b();
                return;
            }

            this.p.setVisibility(View.VISIBLE);
            this.p.setOnClickListener(new f(this));
        }
    }

    private void b() {
        if (this.s == null || this.s.get() == null) {
            g v0 = new g();
            Bundle v1 = new Bundle();
            v1.putLong("id", this.e);
            v1.putLong("update_comment_id", this.f);
            v1.putString("update_user_str", this.g);
            v1.putLong("comment_id", this.h);
            v1.putBoolean("view_comments", this.k);
            v1.putInt("item_type", this.i);
            v1.putInt("update_item_source", this.a);
            v1.putString("explict_desc", this.u);
            v1.putBoolean("show_comment_dialog", this.l);
            v1.putLong("ad_id", this.m);
            v1.putBoolean("replay_zz_comment", this.w);
            v0.setArguments(v1);
            this.getSupportFragmentManager().beginTransaction().replace(com.ss.android.article.browser.R.id.ack, ((Fragment) v0)).commitAllowingStateLoss();
            this.s = new WeakReference(v0);
        }
    }

    private void b(boolean arg2) {
        if (this.isActive()) {
            this.a(arg2);
        } else {
            this.q = true;
            this.r = arg2;
        }
    }

    public final void b(long arg10) {
        long v6 = 0;
        if (arg10 > v6 && this.s != null) {
            Object v0 = this.s.get();
            if (v0 != null) {
                if (arg10 > v6 && ((g) v0).s != null && com.ss.android.article.base.feature.update.activity.g.g$d.g(((g) v0).s) != null && !com.ss.android.article.base.feature.update.activity.g.g$d.g(((g) v0).s).isEmpty()) {
                    Iterator v2 = com.ss.android.article.base.feature.update.activity.g.g$d.g(((g) v0).s).iterator();
                    while (v2.hasNext()) {
                        if (arg10 != ((com.ss.android.article.base.feature.update.a.c) v2.next()).a) {
                            continue;
                        }

                        v2.remove();
                    }

                    ((g) v0).s.notifyDataSetChanged();
                    ((g) v0).c();
                    if (((g) v0).e > v6) {
                        CallbackCenter.notifyCallback(BaseAppData.callbackTypeCommentExtraInfoChanged, new Object[]{BaseAppData.callbackTypeCommentExtraInfoChanged, Long.valueOf(((g) v0).e), Integer.valueOf(((g) v0).j.c), Integer.valueOf(-1), Boolean.valueOf(true)});
                    }
                }

                ((g) v0).c();
            }
        }
    }

    private void c() {
        if (this.x == null) {
            this.x = android.support.design.a.a(this, this.mSwipeOverlay, ac.b(NoDataViewFactory$ImgType.DELETE_ARTICLE), ad.a(this.getString(com.ss.android.article.browser.R.string.comment_deleted_tip)), null, true);
        }

        this.x.initNoDataActionBtn();
        this.x.setVisibility(View.VISIBLE);
        if (this.b) {
            CallbackCenter.notifyCallback(BaseAppData.callbackTypeU11UpdateDetailDeleted, new Object[]{Long.valueOf(this.e)});
        }
    }

    public final void c(long arg4) {
        if (this.isViewValid()) {
            if (arg4 != this.e) {
                if (this.a != 5) {
                    return;
                } else if (arg4 == this.h) {
                } else {
                    return;
                }
            }

            UIUtils.setVisibility(this.o, 8);
            this.b(true);
        }
    }

    public void finish() {
        if (this.n == null || !this.n.d) {
            this.setResult(0);
        } else {
            Intent v0 = new Intent();
            v0.putExtra("comment_id", this.h);
            this.setResult(-1, v0);
        }

        super.finish();
    }

    public int getDayBackgroundRes() {
        return R.color.wj;
    }

    public int getLayout() {
        return R.layout.j5;
    }

    public int getNightBackgroundRes() {
        return R.color.wk;
    }

    public void init() {
        JSONObject v8_1 = null;
        int v8 = 4;
        e v9 = null;
        int v12 = 5;
        long v10 = 0;
        super.init();
        this.c = ((Context) this);
        this.d = UpdateItemMgr.getInstance(this.c);
        UpdateItemMgr v0 = this.d;
        if (this != null) {
            v0.d.add(this);
        }

        this.d.e.add(this);
        this.j = this.d.f;
        Intent v1 = this.getIntent();
        if (v1 != null) {
            this.e = v1.getLongExtra("id", v10);
            this.f = v1.getLongExtra("update_comment_id", v10);
            this.g = v1.getStringExtra("update_user_str");
            this.h = v1.getLongExtra("comment_id", v10);
            this.k = v1.getBooleanExtra("view_comments", false);
            this.i = v1.getIntExtra("item_type", -1);
            this.a = v1.getIntExtra("update_item_source", v8);
            this.t = v1.getStringExtra("gd_ext_json");
            this.u = v1.getStringExtra("explict_desc");
            this.l = v1.getBooleanExtra("show_comment_dialog", false);
            this.m = v1.getLongExtra("ad_id", v10);
            this.w = v1.getBooleanExtra("replay_zz_comment", false);
            boolean v0_1 = v1.getIntExtra("is_from_u11", 0) > 0 ? true : false;
            this.b = v0_1;
            this.v = v1.getLongExtra("item_id", v10);
        }

        if (this.j == null || this.j.a == null || this.j.a.i != this.e) {
            this.j = v9;
        } else {
            this.n = (com.ss.android.article.base.feature.update.a.d) this.j.a;
        }

        if (this.e > v10 && this.n == null) {
            this.n = this.d.b(this.e);
        }

        if ((this.b) && this.n != null) {
            AppData.getInstance().a(this.e, this.n.a, this.n.b, this.n.c);
        }

        if (this.a == v12 || this.e > v10) {
            this.o = this.findViewById(com.ss.android.article.browser.R.id.progress);
            this.p = this.findViewById(com.ss.android.article.browser.R.id.retry);
            if (this.n == null || this.a == v12) {
                this.a(this.a);
            } else {
                this.a(false);
                v0 = this.d;
                d v1_1 = this.n;
                if (v1_1 != null) {
                    v0.i.addTask(Long.valueOf(v1_1.i), v1_1, Integer.valueOf(v8), v9);
                }
            }

            this.mBackBtn.setOnClickListener(new com.ss.android.article.base.feature.update.activity.e(this));
            UIUtils.setVisibility(this.mRightBtn, 8);
            this.mTitleView.setText(this.getResources().getString(com.ss.android.article.browser.R.string.detail_title));
            this.b();
        } else {
            this.finish();
        }

        if (!android.support.design.a.isTextEmpty(this.t)) {
            try {
                v8_1 = new JSONObject(this.t);
            } catch (Exception v0_2) {
            }
        } else {
            v8_1 = ((JSONObject) null);
        }
        if (this.a == v12) {
            MobClickCombiner.onEvent(this, "update_detail", "enter_detail", this.h, v10, v8_1);
        }

        if (this.a == 3) {
            MobClickCombiner.onEvent(this, "topic_detail", "enter", this.e, v10, v8_1);
        } else {
            MobClickCombiner.onEvent(this, "update_detail", "enter", this.e, v10, v8_1);
        }
    }

    public void onBackPressed() {
        if (!this.isFinishing()) {
            Intent v0 = null;
            if (this.isTaskRoot()) {
                v0 = ToolUtils.getLaunchIntentForPackage(((Context) this), this.getPackageName());
            }

            this.finish();
            if (v0 == null) {
                return;
            }

            this.startActivity(v0);
        }
    }

    public void onDestroy() {
        UpdateItemMgr v0 = this.d;
        if (this != null) {
            v0.d.remove(this);
        }

        this.d.e.remove(this);
        super.onDestroy();
    }

    public void onPause() {
        super.onPause();
        if (this.y > 0) {
            long v6 = System.currentTimeMillis() - this.y;
            if (!this.b) {
                return;
            }

            try {
                JSONObject v8 = new JSONObject();
                v8.put("item_id", this.v);
                v8.put("update_item_id", this.n.i);
                v8.put("gtype", 49);
                MobClickCombiner.onEvent(this, "stay_page", "click_headline", 0, v6, v8);
            } catch (Exception v0) {
                v0.printStackTrace();
            }
        }
    }

    public void onResume() {
        super.onResume();
        this.y = System.currentTimeMillis();
        if (this.q) {
            this.q = false;
            this.a(this.r);
        }
    }

    public void onStop() {
        super.onStop();
        if (this.x != null) {
            this.x.b();
        }
    }
}

